import axios from '@/libs/request/axios'
import QS from 'qs';
//获取部门tree
export const initDepartment = (parentId) => {
    return axios.request({
        url: '/admin/applyDepartment/getByParentId',
        data: QS.stringify({parentId:parentId},{arrayFormat: 'repeat'}),
        method: 'post',
        headers: { 'content-type': 'application/x-www-form-urlencoded' },
    })
}

//获取部门tree 不含子节点
export const getDeptByParentId = (parentId) => {
    return axios.request({
        url: '/admin/applyDepartment/getDeptByParentId',
        data: QS.stringify({parentId:parentId},{arrayFormat: 'repeat'}),
        method: 'post',
        headers: { 'content-type': 'application/x-www-form-urlencoded' },
    })
}
// 根据 deptId 获取授权区域
export const getDeptByDeptId = (deptId) => {
    return axios.request({
        url: '/admin/applyDepartment/getDeptByDeptId',
        data: QS.stringify({deptId:deptId},{arrayFormat: 'repeat'}),
        method: 'post',
        headers: { 'content-type': 'application/x-www-form-urlencoded' },
    })
}
//加载新车区域tree
export const initNewCarRegion = (channelId,parentCode,deptParentId) => {
    return axios.request({
        url: '/admin/applyDepartment/loadNewCarRegionData',
        data: QS.stringify({channelId:channelId,parentCode:parentCode,deptParentId:deptParentId},{arrayFormat: 'repeat'}),
        method: 'post',
        headers: { 'content-type': 'application/x-www-form-urlencoded' },
    })
}
//加载二手车区域tree
export const initOldCarRegion = (channelId,parentCode,deptParentId) => {
    return axios.request({
        url: '/admin/applyDepartment/loadOldCarRegionData',
        data: QS.stringify({channelId:channelId,parentCode:parentCode,deptParentId:deptParentId},{arrayFormat: 'repeat'}),
        method: 'post',
        headers: { 'content-type': 'application/x-www-form-urlencoded' },
    })
}
// 添加部门
export const addDepartment = (params) => {
    return axios.request({
        url: '/admin/applyDepartment/add',
        data: params,
        method: 'post'
    })
}
// 编辑部门
export const editDepartment = (params) => {
    return axios.request({
        url: '/admin/applyDepartment/edit',
        data: params,
        method: 'post'
    })
}
// 删除部门
export const deleteDepartment = (ids, params) => {
    return axios.request({
        url: `/admin/applyDepartment/delByIds/${ids}`,
        params: params,
        method: 'delete'
    })
}

// 删除部门
export const delByIdDepartment = (id, params) => {
    return axios.request({
        url: `/admin/applyDepartment/delById/${id}`,
        params: params,
        method: 'delete'
    })
}
// 搜索部门
export const searchDepartment = (title) => {
    return axios.request({
        url: '/admin/applyDepartment/search',
        data: QS.stringify({title:title},{arrayFormat: 'repeat'}),
        method: 'post',
        headers: { 'content-type': 'application/x-www-form-urlencoded' },
    })
}

// 搜索查询渠道自己的部门
export const channelSearch = (title) => {
    return axios.request({
        url: '/admin/applyDepartment/channelSearch',
        data: QS.stringify({title:title},{arrayFormat: 'repeat'}),
        method: 'post',
        headers: { 'content-type': 'application/x-www-form-urlencoded' },
    })
}
